<!--
 * @Descripttion: 订单管理
 * @version:
 * @Author: 赵致喜
 * @Date: 2020-10-12 18:48:41
 * @LastEditors: 穆宏宇
 * @LastEditTime: 2020-11-26 19:07:10
-->
<template>
	<div class="bigDiv">
		<div class="topNav">
			<el-button @click="addControlHandle" type="text">新增</el-button>
		</div>
		<div class="table-box">
			<el-table :data="tableData" border @selection-change="handleSelectionChange" height="calc(100vh - 220px)">
				<el-table-column type="selection" width="50"></el-table-column>
				<el-table-column prop="title" label="标题"></el-table-column>
				<el-table-column prop="content" label="内容"></el-table-column>
				<el-table-column prop="company" label="发布单位"></el-table-column>
				<el-table-column prop="times" label="发布时间"></el-table-column>
				<el-table-column label="操作" width="250" fixed="right">
					<template slot-scope="scope">
						<el-button @click="updateIt(scope.row)" size="mini">修改</el-button>
					</template>
				</el-table-column>
			</el-table>
			<el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
				:page-size="pageData.pageSize" layout="total, sizes, prev, pager, next, jumper" :total="pageData.total"
				style="text-align: right;">
			</el-pagination>
		</div>
		<el-dialog title="加价信息" :visible.sync="paperDialogShow" width="1200px">
			<el-form label-position="'right'" label-width="120px" label-suffix=":" v-model="paperDict">
				<el-form-item label="标题">
					<el-input v-model="paperDict.title" type="text"  />
				</el-form-item>
				<el-form-item label="内容">
					<el-input v-model="paperDict.content" type="text"  />
				</el-form-item>
				<el-form-item label="发布单位">
					<el-input v-model="paperDict.company" type="text"  />
				</el-form-item>
				<el-form-item label="发布时间">
					<el-input v-model="paperDict.times" type="text"  />
				</el-form-item>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button type="primary" @click="submitHandle()">保存</el-button>
			</div>
		</el-dialog>
	</div>
</template>

<script>
	import {
		selecleftBottomAd,inserleftBottomAd,edileftBottomAd
	} from '@/api/admin.api'
	import moment from 'moment'
	export default {
		name: 'supplierReconciliation',
		data() {
			return {
				searchFormData: {
					orgId:"",
					purchaseId:"",
					status:0
				},
				// tableData: [],
				tableData: [],
				tableData2: [],
				// 分页数据
				pageData: {
					// 当前分页
					pageNum: 1,
					// 分页条数
					pageSize: 10,
					// 数据总数
					total: 0,
				},
				pageData2: {
					// 当前分页
					pageNum: 1,
					// 分页条数
					pageSize: 10,
					// 数据总数
					total: 0,
				},
				// 表格选中数据
				tableSelectData: [],
				tableSelectData2: [],
				remarkDialogShow: false,
				paperDialogShow: false,
				remark: "",
				paperDict: {
					title:'',
					content:'',
					company:"",
					times:''
				},
				purchaseList:[],
				userList:[],
			}
		},
		methods: {
			updateIt(row){
				var that = this;
				this.paperDict = row;
				this.paperDialogShow = true;
			},
			deleteIt(row){
				this.$confirm('是否删除加价模板, 是否继续?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then((data) => {
					delOrderManagementDiscount({
						id:row.id
					}).then((res) => {
						console.log(res);
						this.$message({
							type: 'success',
							message: '删除成功!'
						});
						this.getTableData();
						this.paperDialogShow = false;
					})
				})
				
			},
			addControlHandle(){
				if(this.tableData.length > 0){
					this.$message({
						type: 'error',
						message: '已经有一条记录了，您只能修改!'
					});
				}else{
					this.paperDict = {};
					this.tableData2 = [];
					this.paperDialogShow = true;
				}
			},
			submitHandle(remark) {
				// 这里还要记录相同组织的用户的加价信息，数组拼接  新增和修改
				var that = this;
				if(this.paperDict.id){
					edileftBottomAd(this.paperDict).then((res) => {
						console.log(res);
						this.$message({
							type: 'success',
							message: '修改成功!'
						});
						this.getTableData();
						this.paperDialogShow = false;
					})
				}else{
					inserleftBottomAd(this.paperDict).then((res) => {
						console.log(res);
						this.$message({
							type: 'success',
							message: '新增成功!'
						});
						this.getTableData();
						this.paperDialogShow = false;
					})
				}
				
			},
			// 检索订单管理列表
			searchControlHandle() {
				this.getTableData()
			},
			handleSizeChange(val) {
				this.pageData.pageSize = val
				this.getTableData()
			},
			handleSizeChange2(val) {
				this.pageData2.pageSize = val
				this.getTableData()
			},
			handleCurrentChange(val) {
				this.pageData.pageNum = val
				this.getTableData()
			},
			handleCurrentChange2(val) {
				this.pageData2.pageNum = val
				this.getTableData()
			},
			handleSelectionChange(val) {
				this.multipleSelection = val;
				console.log(val)
			},
			handleSelectionChange2(val) {
				this.multipleSelection2 = val;
				console.log(val)
			},
			// 重置搜索条件
			refreshControlHandle() {
				this.searchFormData = {}
				this.getTableData()
			},
			// 请求订单管理列表
			getTableData() {
				const newSearch = {
					...this.searchFormData,
					...this.pageData,
				}
				console.log(newSearch);
				selecleftBottomAd(newSearch).then((res) => {
					console.log(res.rows)
					this.tableData = res.rows;
					this.pageData.total = res.total;
				})
			},
		},
		created() {},
		mounted() {
			this.getTableData()
		},
	}
</script>

<style>
	.el-button--text {
		display: none;
	}
</style>
